<template>
	<div>
		<el-tabs v-model="activeName" @tab-click="handleTabChange">
			<el-tab-pane label="基础信息" name="BaseDetail"></el-tab-pane>
			<el-tab-pane label="扩展信息" name="Extend"></el-tab-pane>
			<el-tab-pane label="其他信息" name="Other"></el-tab-pane>
			<el-tab-pane label="评价记录" name="EvaluationRecords"></el-tab-pane>
			<!-- <el-tab-pane label="年审记录" name="AnnualAudit"></el-tab-pane> -->
			<el-tab-pane label="从业人员" name="practitioner"></el-tab-pane>
			<div class="content-card">
				<html-label :title="activeLabelTitle">
					<div v-if="!(nowRowData.dataStatus && nowRowData.dataStatus !== '0') && ['BaseDetail', 'Extend', 'Other'].includes(activeName)">
						<el-button type="primary" plain @click="handleOperate('edit')"> 信息变更 </el-button>
					</div>
				</html-label>

				<component :is="whickComm[activeName]" :actionBtn="false" :searchConfig="false" :ifShowSearch="false" v-bind="$attrs"></component>
			</div>
		</el-tabs>
	</div>
</template>

<script setup lang="ts">
import BaseDetail from '@/views/datacenter/basicData/serviceOrg/components/Archives/BaseDetail/index.vue'
import Extend from '@/views/datacenter/basicData/serviceOrg/components/Archives/Extend/index.vue'
import Other from '@/views/datacenter/basicData/serviceOrg/components/Archives/Other/index.vue'
import EvaluationRecords from './evaluationRecords/index.vue'
import practitioner from './practitioner/index.vue'
import { baseConfig } from '../../config'
import { useOperate } from '@/views/datacenter/hooks/useConfig'
import { useCommonStore } from '@/stores/common'
import bus from '@/utils/eventbus'

const { setTempParams, setMoreSearch } = useCommonStore()
const { onDelete, onMessageChange } = useOperate(2)
const whickComm = {
	BaseDetail,
	Extend,
	Other,
	EvaluationRecords,
	practitioner,
}
const activeName = ref('BaseDetail')
type Props = {
	nowRowData?: any
}

const props = withDefaults(defineProps<Props>(), {})
provide('nowRowData', props.nowRowData)

setMoreSearch({
	params: {
		creditCode: props.nowRowData.creditCode,
	},
})

const emit = defineEmits(['refresh', 'rechange'])
const activeLabelTitle = ref('基本信息')
const openEdit = () => {
	onMessageChange().then(() => {
		const activeStr = {
			BaseDetail: 1,
			Extend: 2,
			Other: 3,
		}
		setTempParams({
			name: props.nowRowData.organizationName,
			organizationName: props.nowRowData.organizationName,
			creditCode: props.nowRowData.creditCode,
			active: activeStr[activeName.value] || 1,
		})
		emit('rechange', 'Rechange', props.nowRowData, '信息变更数据')
	})
}

const handleOperate = (type) => {
	if (type == 'delete') {
		onDelete(props.nowRowData[baseConfig.rowKey], baseConfig.api.delete, props.nowRowData.organizationName).then(() => {
			emit('refresh')
		}).catch(()=> {
      return
    })
		return
	}
	openEdit()
}

const handleTabChange = (tab) => {
	activeLabelTitle.value = tab.props.label
	setMoreSearch({
		params: {
			creditCode: props.nowRowData.creditCode,
		},
	})
}
bus.on('menu-operate', (res) => {
  if(res.pageName ==baseConfig.pageName) {
	  handleOperate(res.operate)
  }
})

onUnmounted(() => {
	setMoreSearch({})
})
</script>

<style scoped></style>
